﻿/*
 * Name:        GFXBuffer
 * Description: A buffer used for rendering the scene
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

using Gyvate.Util;

namespace Gyvate.GFX
{
    public class GFXBuffer
    {
        private Image m_buffer;
        private Graphics m_gfx;

        public Graphics GetFX() { return m_gfx; }
        public Image GetBuffer() { return m_buffer; }

        /*
         * Constructor
         * Parameters:
         *  sizeMainPanel - used to override, this was added for UI
         */
        public GFXBuffer(Vector2d size = null)
        {

            if (Object.ReferenceEquals(size, null))
            {
                size = new Vector2d();

                size.x = (Constants.FIELD_WIDTH + 1) * Constants.SPRITE_SIZE;
                size.y = (Constants.FIELD_HEIGHT + 1) * Constants.SPRITE_SIZE;
            }

            m_buffer = new Bitmap(size.x, size.y);
            m_gfx = Graphics.FromImage(m_buffer);
        }

        /*
         * Renders the world
         * Parameters:
         *  draw - takes graphics system input in which it draws
         */
        public void Render(Graphics draw)
        {
            m_gfx = Graphics.FromImage(m_buffer);

            m_gfx.Dispose();

            draw.DrawImage(m_buffer, 0, 0);

            m_gfx = Graphics.FromImage(m_buffer);
        }
    }
}
